package com.thinkgem.jeesite.modules.crawler.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
/**
 * 时间相关类
 * 请使用本类
 * @author clz
 * @date 2015-6-16
 */
public class DateUtil {

    // 用来全局控制 上一周，本周，下一周的周数变化
    private static int weeks = 0;
    //日期格式 yyyy-MM-dd
    public final static String datePattern = "yyyy-MM-dd";
    
    //时间格式 yyyy-MM-dd HH:mm
    public final static String timePattern = "yyyy-MM-dd HH:mm";
	
	//默认格式 yyyy-MM-dd HH:mm:ss
	public final static String defaultPattern = "yyyy-MM-dd HH:mm:ss";
	
	public final static String yearPattern = "yyyy";
	
	public final static String monthPattern = "MM";
	
	public final static String dayPattern = "dd";
    
    /**
     * 获得当前日期与本周一相差的天数
     * @autor tcl
     * Aug 15, 2008
     * @return
     * int
     */
    public static final int getMondayPlus() {
        Calendar cd = Calendar.getInstance();
        // 获得今天是一周的第几天，星期日是第一天，星期二是第二天......
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == 1) {
            return -6;
        } else {
            return 2 - dayOfWeek;
        }
    }
    
    /**
     * 获取当前日期
     * 格式：2017-09-09
     * @return
     */
    public static final String getCurrentDate(){
    	return DateUtil.formatDateToString(new Date(), "yyyy-MM-dd");
    }

    /**
     * 获得上周星期一的日期
     * @autor tcl
     * Aug 15, 2008
     * @return
     * String
     */
    public static final String getPreviousMonday() {
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * ( weeks - 1 ));
        Date monday = currentDate.getTime();
        String preMonday = convertDateToString(datePattern,monday);
        return preMonday;
    }
    
    /**
     * 获得上周星期日的日期
     * @autor tcl
     * Aug 15, 2008
     * @return
     * String
     */
    public static final String getPreviousSunday() {
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus  - 1 );
        Date monday = currentDate.getTime();
        String preMonday = convertDateToString(datePattern,monday);
        return preMonday;
    }

    /**
     * 获得本周星期一的日期
     * @autor tcl
     * Aug 15, 2008
     * @return
     * String
     */
    public static final String getCurrentMonday() {
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus);
        Date monday = currentDate.getTime();
        String preMonday = convertDateToString(datePattern,monday);
        return preMonday;
    }
    
    /**
     * 获得本周的周日的日期
     * @autor tcl
     * Aug 15, 2008
     * @return
     * String
     */
    public static final String getCurrentSunday() {
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 6 );
        Date monday = currentDate.getTime();
        String preMonday = convertDateToString(datePattern,monday);
        return preMonday;
    } 

    /**
     * 获得下周星期一的日期
     * @autor tcl
     * Aug 15, 2008
     * @return
     * String
     */
    public static final String getNextMonday() {
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * ( weeks + 1 ));
        Date monday = currentDate.getTime();
        String preMonday = convertDateToString(datePattern,monday);
        return preMonday;
    }
    
    /**
     * 获得下周星期日的日期
     * @autor tcl
     * Aug 15, 2008
     * @return
     * String
     */
    public static final String getNextSunday() {
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * ( weeks + 1 ) + 6);
        Date monday = currentDate.getTime();
        String preMonday = convertDateToString(datePattern,monday);
        return preMonday;
    }
    
    /**
     * 获得与当前日期相隔N天的日期
     * @autor tcl
     * Aug 15, 2008
     * @param n n=0:当日, n<0:前n日, n>0:后n日
     * @return
     * String
     */
    public static final String getDate(int n) {
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, n);
        Date monday = currentDate.getTime();
        String preMonday = convertDateToString(datePattern,monday);
        return preMonday;
    }
    
    
    /**
     * 获得某年某月的月初日期
     * @autor tcl
     * Aug 15, 2008
     * @param year
     * @param month
     * @return
     * String
     */
    public static final String getMonthStart(int year,int month) { 
    	Calendar cal = Calendar.getInstance(); 
    	cal.set(Calendar.YEAR, year);// 年 
    	cal.set(Calendar.MONTH, month - 1);// 月，因为Calendar里的月是从0开始，所以要减1 
    	cal.set(Calendar.DATE, 1);// 日，设为一号 
    	String preMonday = convertDateToString(datePattern,cal.getTime());
    	return preMonday;// 获得月末是几号 
    }
    
    /**
     * 获得某年某月的月末日期
     * @autor tcl
     * Aug 15, 2008
     * @param year
     * @param month
     * @return
     * String
     */
    public static final String getMonthEnd(int year,int month) { 
    	Calendar cal = Calendar.getInstance(); 
    	cal.set(Calendar.YEAR, year);// 年 
    	cal.set(Calendar.MONTH, month - 1);// 月，因为Calendar里的月是从0开始，所以要减1 
    	cal.set(Calendar.DATE, 1);// 日，设为一号 
    	cal.add(Calendar.MONTH, 1);// 月份加一，得到下个月的一号 
    	cal.add(Calendar.DATE, -1);// 下一个月减一为本月最后一天 
    	String preMonday = convertDateToString(datePattern,cal.getTime());
    	return preMonday;// 获得月末是几号 
    }

    
    /**
     * 获得当前日
     * @autor tcl
     * Aug 15, 2008
     * @return
     * int
     */
    public static final int getCurrentDay(){
    	Calendar cal = Calendar.getInstance(); 
    	int date=cal.get(cal.DATE);
    	return date;
    }
    

    /**
     * 获得当前星期几
     * @return 返回2代表今天是星期2
     */
    public static final int getCurrentDayOfWeek(){
    	Calendar cal = Calendar.getInstance(); 
    	int today=cal.get(cal.DAY_OF_WEEK)-1; 
    	return today;    	
    }
    
    /**
     * 获得时间的格式
     * @autor tcl
     * Aug 15, 2008
     * @param pattern
     * @return
     * String
     */
    private static final String getPattern(String pattern) {
    	String p = defaultPattern;
        if (pattern != null && !pattern.trim().equals(""))
        	p = pattern;
		return p;
	}
    
    /**
     * 把字符串格式转化成时间格式
     * @autor tcl
     * Aug 15, 2008
     * @param pattern 需要转成的显示格式 yyyy-MM-dd HH:mm:ss,yyyy-MM-dd ...
     * @param strDate 待转的字符串
     * @return
     * @throws ParseException
     * Date
     */
    public static final Date convertStringToDate(String pattern, String strDate) throws ParseException {
		Date date = null;
		SimpleDateFormat df = new SimpleDateFormat(pattern);
		try {
			date = df.parse(strDate);
		} catch (ParseException pe) {
			throw new ParseException(pe.getMessage(), pe.getErrorOffset());
		}
		
		return date;
	}
    
    /**
     * 把字符串格式转化成时间格式
     * @autor tcl
     * Aug 15, 2008
     * @param strDate 待转的字符串
     * @return
     * @throws ParseException
     * Date
     */
    public static final Date convertStringToDate(String strDate) throws ParseException {
		SimpleDateFormat df = null;
		Date date = null;
		df = new SimpleDateFormat(datePattern);
		try {
			date = df.parse(strDate);
		} catch (ParseException pe) {
			throw new ParseException(pe.getMessage(), pe.getErrorOffset());
		}

		return (date);
	}
    
    public static final Date convertStringToDateTime(String strDate) throws ParseException {
		SimpleDateFormat df = null;
		Date date = null;
		df = new SimpleDateFormat(defaultPattern);
		try {
			date = df.parse(strDate);
		} catch (ParseException pe) {
			throw new ParseException(pe.getMessage(), pe.getErrorOffset());
		}

		return (date);
	}
    
    /**
     * 把时间格式转换成字符串格式
     * @param pattern 需要转成的显示格式 yyyy-MM-dd HH:mm:ss,yyyy-MM-dd ...
     * @param aDate 待转的时间
     * @return
     * String
     */
    public static final String convertDateToString(String pattern, Date aDate) {
		SimpleDateFormat df = null;
		String returnValue = "";
		pattern = getPattern(pattern);
		if (aDate != null) {
			df = new SimpleDateFormat(pattern);
			returnValue = df.format(aDate);
		}

		return (returnValue);
	}
    
    public static final String convertDateToStringYmd(Date aDate) {
		SimpleDateFormat df = null;
		String returnValue = "";
		if (aDate != null) {
			df = new SimpleDateFormat(datePattern);
			returnValue = df.format(aDate);
		}

		return (returnValue);
	}
    
    /**
     * 把时间格式转换成字符串格式
     * @param aDate 待转的时间
     * @return
     * String
     */
    public static final String convertDateToString(Date aDate) {
		SimpleDateFormat df = null;
		String returnValue = "";
		if (aDate != null) {
			df = new SimpleDateFormat(defaultPattern);
			returnValue = df.format(aDate);
		}

		return (returnValue);
	}
    



    
    /**
     * 取得当前日期所在周的第一天
     *
     * @param date
     * @return
     */
    public static Date getFirstDayOfWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.SUNDAY);
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_WEEK,
                      calendar.getFirstDayOfWeek()); // Sunday
        return calendar.getTime();
    }

    /**
     * 取得当前日期所在周的最后一天
     *
     * @param date
     * @return
     */
    public static Date getLastDayOfWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.SUNDAY);
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_WEEK,
                     calendar.getFirstDayOfWeek() + 6); // Saturday
        return calendar.getTime();
    }

    
    /**
     * 返回指定日期的月的第一天
     *
     * @param year
     * @param month
     * @return
     */
    public static Date getFirstDayOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(calendar.get(Calendar.YEAR),
                     calendar.get(Calendar.MONTH), 1);
        return calendar.getTime();
    }

    /**
     * 返回指定年月的月的第一天
     *
     * @param year
     * @param month
     * @return
     */
    public static Date getFirstDayOfMonth(Integer year, Integer month) {
        Calendar calendar = Calendar.getInstance();
        if (year == null) {
            year = calendar.get(Calendar.YEAR);
        }
        if (month == null) {
            month = calendar.get(Calendar.MONTH);
        }
        calendar.set(year, month, 1);
        return calendar.getTime();
    }
    
    
    /**
     * 返回指定年季的季的第一天
     *
     * @param year
     * @param quarter
     * @return
     */
    public static Date getFirstDayOfQuarter(Integer year, Integer quarter) {
        Calendar calendar = Calendar.getInstance();
        Integer month = new Integer(0);
        if (quarter == 1) {
            month = 1 - 1;
        } else if (quarter == 2) {
            month = 4 - 1;
        } else if (quarter == 3) {
            month = 7 - 1;
        } else if (quarter == 4) {
            month = 10 - 1;
        } else {
            month = calendar.get(Calendar.MONTH);
        }
        return getFirstDayOfMonth(year, month);
    }

    /**
     * 返回指定年季的季的最后一天
     *
     * @param year
     * @param quarter
     * @return
     */
    public static Date getLastDayOfQuarter(Integer year, Integer quarter) {
        Calendar calendar = Calendar.getInstance();
        Integer month = new Integer(1);
        if (quarter == 1) {
            month = 3;
        } else if (quarter == 2) {
            month = 6;
        } else if (quarter == 3) {
            month = 9;
        } else if (quarter == 4) {
            month = 12;
        } else {
            month = calendar.get(Calendar.MONTH);
        }
        return getLastDayOfMonth(year, month-1);
    }
    
    /**
     * 返回指定年月的月的最后一天
     *
     * @param year
     * @param month从0开始
     * @return
     */
    public static Date getLastDayOfMonth(Integer year, Integer month) {
        Calendar calendar = Calendar.getInstance();
        if (year == null) {
            year = calendar.get(Calendar.YEAR);
        }
        if (month == null) {
            month = calendar.get(Calendar.MONTH);
        }
        calendar.set(year, month, 1);
        calendar.roll(Calendar.DATE, -1);
        return calendar.getTime();
    }
    
    
    
    
    
    
	/**
	 * 获取某年某月天数
	 * @param year
	 * @param month
	 * @return
	 */
	public static Integer getDayCountsOfMonth(Integer year,Integer month){
		if(year==null||month==null)
			return 0;
		Calendar time=Calendar.getInstance(); 
		time.clear(); 
		time.set(Calendar.YEAR,year); 
		time.set(Calendar.MONTH,month-1);
		return time.getActualMaximum(Calendar.DAY_OF_MONTH);
	}
	
	/**
	 * 计算该日期是属于一年中的第几个季度
	 * @param data
	 * @return
	 */
	public static Integer getYearOfQuarter(Date date){
		if(date==null)
			return null;
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		Integer month = c.get(Calendar.MONTH)+1;
		if(month==1||month==2||month==3){
			return 1;
		}else if(month==4||month==5||month==6){
			return 2;
		}else if(month==7||month==8||month==9){
			return 3;
		}else if(month==10||month==11||month==12){
			return 4;
		}
		return null;
	}
	
	/**
	 * 计算属于一年中的第几旬（从1...36 ）
	 * @param date
	 * @return
	 */
	public static Integer getYearOfTenDays(Date date){
		if(date==null)
			return null;
	    Integer month = getMonthFromDate(date);
	    Integer tenDaysTemp = getMonthOfTenDays(date);
	    return (month-1)*3+tenDaysTemp;
	}
	
	/**
	 * 计算该日期是当月中的哪一旬
	 * @param date
	 * @return
	 */
	public static Integer getMonthOfTenDays(Date date){
		if(date==null)
			return null;
		
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		Integer day = c.get(Calendar.DAY_OF_MONTH);
		if(day<=10)
			return 1;
		if(11<=day&&day<=20)
			return 2;
		if(day>=20)
			return 3;
		return null;
	}
	
	/**
	 * 今天为该年中的那一旬（1~36）
	 * @param date
	 * @return
	 */
	public static Integer getYearTenDays(Date date){
		if(date==null)
			return null;
		Integer month = getMonthFromDate(date);
		Integer monthOfTenDays = getMonthOfTenDays(date);
		return (month-1)*3+monthOfTenDays;
	}
	
	/**
	 * 计算该日期为该年的第几周
	 * 周一一周的第一天
	 * @param date
	 * @return
	 */
	public static Integer getWeekOfYear(Date date){
		if(date==null)
			return null;
		Calendar c = Calendar.getInstance();
		c.setFirstDayOfWeek(Calendar.MONDAY);
		c.setTime(date);
		Integer week = c.get(Calendar.WEEK_OF_YEAR);
		return week;
	}
	
	/**
	 * 格式化时间-->日期。
	 * @param date
	 * @return yyyy-MM-dd 格式
	 */
	public static Date formatDate(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String d = sdf.format(date);
		try {
			return sdf.parse(d);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 时间格式化
	 * @param date
	 * @param format
	 * @return
	 */
	public static Date formatDate(Date date,String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		String d = sdf.format(date);
		try {
			return sdf.parse(d);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	
	public static Integer getYearFromDate(Date date) {	
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.YEAR);
	}
	
	public static Integer getMonthFromDate(Date date) {	
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.MONTH)+1;
	}
	
	public static Integer getDayOfMonthFromDate(Date date) {	
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.DAY_OF_MONTH);
	}
	
	public static Integer getDayOfYearFromDate(Date date) {	
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.DAY_OF_YEAR);
	}
	
	public static Integer getQuarterFromDate(Date date) {	
	   Integer month = DateUtil.getMonthFromDate(date);
	   
	   if(month>=1&&month<=3){
		   return 1;
	   }else if(month>=4&&month<=6){
		   return 2; 
	   }else if(month>=7&&month<=9){
		   return 3; 
	   }else if(month>=10&&month<=12){
		   return 4; 
	   }else{
		   return -1;
	   }
	   
	}
	
	
	/**
	 * 字符串转日期
	 * @param str
	 * @return
	 */
	public static Date stringToDate(String str) {
		if(StringUtils.isEmpty(str)){
			return new Date();
		}	
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
		Date date = sdf.parse(str);
	    return date;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	   /**
  *  时间前后推
  * @param date
  * @param yearLen  可正、可负
  * @param monthLen   可正、可负
  * @param dayLen    可正、可负
  * @return
  * @throws Exception
  */
   public static Date getDate(Date date,int yearLen,int monthLen,int dayLen) throws Exception
     {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(date);
         if(yearLen!=0){
             calendar.add(Calendar.YEAR,yearLen);
         }
         if(monthLen!=0){
             calendar.add(Calendar.MONTH,monthLen);
         }
         if(dayLen!=0){
             calendar.add(Calendar.DATE,dayLen);
         }
      return calendar.getTime();
     }
   
	
	public static Integer getCurrentYear(){
		Calendar c = Calendar.getInstance();
		return c.get(Calendar.YEAR);
	}
	
	public static Integer getCurrentMonth(){
		Calendar c = Calendar.getInstance();
		return c.get(Calendar.MONTH)+1;
	}
	
	public static Integer getCurrentQuarter() {
		int m = getCurrentMonth();
		switch (m) {
			case 1:
			case 2:
			case 3:
				m = 1;
				break;
			case 4:
			case 5:
			case 6:
				m = 2;
				break;
			case 7:
			case 8:
			case 9:
				m = 3;
				break;
			case 10:
			case 11:
			case 12:
				m = 4;
				break;
			default:
				m = 1;
		}
		return m;
	}
	
	
	
	/**
	 * 当日开始时间
	 * @return
	 */
	public static String  getDayStart(Date date){
		String dateStr = DateUtil.formatDateToString(date, "yyyy-MM-dd");	
		return dateStr+" 00:00:00";
	}
	/**
	 * 当日结束时间
	 * @return
	 */
	public static String  getDayEnd(Date date){
		String dateStr = DateUtil.formatDateToString(date, "yyyy-MM-dd");	
		return dateStr+" 23:59:59";
	}
	
	/**
	 * 当月开始时间 如：2015-05-01 00:00:00
	 * @return
	 */
	public static String  getMonthStart(Date date){
		String dateStr = DateUtil.formatDateToString(date, "yyyy-MM");
		return dateStr+"-"+"01"+" 00:00:00";
	}
	/**
	 * 一个与月的最后一天
	 * 时间格式为 yyyy-MM-dd HH:mm:ss
	 * @param date
	 * @return
	 */
	public static String  getMonthEnd(Date date){
		String dateStr = DateUtil.formatDateToString(date, "yyyy-MM");
		
		Calendar c = Calendar.getInstance();
		c.setTime(date);
	    Integer day = c.get(Calendar.DAY_OF_MONTH);
		return dateStr+"-"+(day<10?("0"+day):day)+" 23:59:59";
	}
	
	/**
	 * 当年开始
	 * @return
	 */
	public static String  getYearStart(Date date){
		String dateStr = DateUtil.formatDateToString(date, "yyyy");
		return dateStr+"-"+"01"+"-"+"01"+" 00:00:00";
	}
	
	/**
	 * 当年结束
	 * 时间格式为 yyyy-MM-dd HH:mm:ss
	 * @return
	 */
	public static String  getYearEnd(Date date){
		String dateStr = DateUtil.formatDateToString(date, "yyyy-MM");
		return dateStr+"-"+"31"+" 23:59:59";
	}
	
	public static String formatDateToString(Date date, String format) {
		if (date == null) {
			date = new Date();
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	
	/**
	 * 返回当前日期时间的字符串<br>
	 * 时间格式为 yyyy-MM-dd HH:mm:ss
	 */
	public static String getCurrentTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date d = new Date();
		return sdf.format(d);
	}
	
	public static String getNoSerial() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		Date d = new Date();
		return sdf.format(d);
	}
	
    
    
	/**
	 * 判断是否是一周的开始（第一天,周日）
	 * @param date
	 * @return
	 */
	public static Boolean isWeekStart(Date date){
		 Calendar cal = Calendar.getInstance();
		 cal.setTime(date);
		 if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)
			 return true;
		 return false;
	}
	/**
	 * 是否一个月开始
	 * @param date
	 * @return
	 */
	public static Boolean isMonthStart(Date date){
		String day = DateUtil.formatDateToString(date,"dd");
		if("01".equals(day))
			return true;
		return false;
	}
	
	/**
	 * 是否一个月结束
	 * @param date
	 * @return
	 */
	public static Boolean isMonthEnd(Date date){
		Integer year = DateUtil.getYearFromDate(date);
		Integer month = DateUtil.getMonthFromDate(date);	
		Date lastDate = DateUtil.getLastDayOfMonth(year, month-1);
		String dateStr = DateUtil.convertDateToString("yyyy-MM-dd",date);
		String lastDateStr = DateUtil.convertDateToString("yyyy-MM-dd",lastDate);		
		if(dateStr.equals(lastDateStr))
			return true;
		return false;
		
	}
	
	/**
	 * 是否一个旬的开始
	 * @param date
	 * @return
	 */
	public static Boolean isTenDaysStart(Date date){
		String day = DateUtil.formatDateToString(date,"dd");
		if("01".equals(day)||"11".equals(day)||"21".equals(day))
			return true;
		return false;
	}
	
	
	/**
	 * 是否一个季度的开始
	 * @param date
	 * @return
	 */
	public static Boolean isQuarterStart(Date date){
		String monthAndDay = DateUtil.formatDateToString(date,"MM-dd");
		if("01-01".equals(monthAndDay)||"04-01".equals(monthAndDay)||"07-01".equals(monthAndDay)||"10-01".equals(monthAndDay))
			return true;
		return false;
	}
	
	/**
	 * 是否一个季度的结束
	 * @param date
	 * @return
	 */
	public static Boolean isQuarterEnd(Date date){
		Integer quarter = DateUtil.getQuarterFromDate(date);
		if(quarter==3||quarter==6||quarter==9||quarter==12){
			return DateUtil.isMonthEnd(date);
		}
		return false;
	}
	
	
	
	/**
	 * 是否半年开始
	 * @param date
	 * @return
	 */
	public static Boolean isHalfYearStart(Date date){
		String monthAndDay = DateUtil.formatDateToString(date,"MM-dd");
		if("01-01".equals(monthAndDay)||"07-01".equals(monthAndDay))
			return true;
		return false;
	}
	/**
	 * 是否一年的开始
	 * @param date
	 * @return
	 */
	public static Boolean isYearStart(Date date){
		String monthAndDay = DateUtil.formatDateToString(date,"MM-dd");
		if("01-01".equals(monthAndDay))
			return true;
		return false;
	}

	
	/**
	 * 获取日期前数天的日期列表
	 * @author mj 2017/5/24
	 * @param  date
	 * @param  preNum
	 * @return preDateList
	 */
	public static List<Date> getPreDateList(Date date, int preNum) {
		if(date == null) {
			return null;
		}
		if(preNum <= 0) {
			preNum = 10;
		}
		List<Date> preDateList = new ArrayList<Date>();
		for(int i=preNum-1; i>=0; i--) {
			try {
				Date preDate = DateUtil.getDate(date, 0, 0, -i);
				preDateList.add(preDate);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return preDateList;
	}
	
	/**
	 * 将给定日期转换为指定格式的字符串，如：2017-2
	 * @author mj 2017/5/15
	 * @param  date
	 * @return dateStr
	 */
	public static String getDateStr(Date date){
		if(date == null){
			return null;
		}
		String dateStr = "";
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 1;
		dateStr = year + "-" + month;
		return dateStr;
	}
}
